package view.role
{
	import control.manager.LayerManager;
	import control.manager.RoleManager;
	import control.manager.TaskManager;
	
	import data.MonsterData;
	import data.RoleVO;
	
	import view.layer.GameLayer;

	public class MapMonster extends MapObject
	{
		
		public var monsterData :MonsterData;
		/**
		 * 怪物当前血量 
		 */		
		public var curHP :int;
		public function MapMonster(monsterData :MonsterData)
		{

			super(monsterData);
			this.monsterData = monsterData;
			this.curHP = monsterData.monsterHP;
			
		}
		
		override public function update():void
		{
			super.update();
		}
		
		override public function setRoleLife(value:Number,hp :int):void
		{
			this.roleLife.setLife(value,hp);
			this.curHP -= value;
			if(this.curHP <= 0)
			{
				TaskManager.instance.checkTaskIsCompelte(this);
				this.isAlive = false;
				this.visible = false;
				var player :MapPlayer = gameLayer.player;
				player.curStatus = MapPlayer.NORMAL;
				player.curClickObj = null;
				newMonster();
				return;
			}
			
		}
		
		override public function hurt(value :Number):void
		{
			trace("被击中");
			setRoleLife(value,this.monsterData.monsterHP);
		}
		/**
		 * 重新生成一个怪在原来的位置 
		 * 
		 */		
		private function newMonster():void
		{
			var monster :MapMonster = new MapMonster(this.monsterData);
			monster.x = this.x;
			monster.y = this.y;
			RoleManager.instance.addRole(monster);
		}
		
		private function get gameLayer():GameLayer
		{
			var gameLayer :GameLayer = LayerManager.instance.getLayer(GameLayer.NAME) as GameLayer;
			return gameLayer;
		}
	}
}